<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
	<%@include file="/view/resource.jsp" %>
	<link rel="stylesheet" type="text/css" href="${ctx}/css/base.css">
	<link rel="stylesheet" href="${ctx}/static/plugins/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css">
	<script type="text/javascript" src="${ctx}/static/plugins/ztree/js/jquery.ztree.core.js"></script>
	<script type="text/javascript" src="${ctx}/static/plugins/ztree/js/jquery.ztree.excheck.js"></script>
	<style type="text/css">
		.btnmr {
			margin-right: 5px;
		}

		.panel-tool a.layout-button-up {
			display: none;
		}

	</style>
</head>
<body>
<div class="topjui-layout" data-options="fit:true">
	<div data-options="region:'west',split:false,width:290">
		<div title="" style="padding: 3px">
			<span style="margin-left: 100px;font-size:14px;color: #330099;">指挥卡树形</span>
			<div id="p" style="margin-bottom: 5px">
				<select class="topjui-combobox" name="filterType" id="filterType" style="width: 120px;"
				        data-options="panelHeight:105,value:'0'">
					<option value="设备号">设备号</option>
					<option value="显示名称">显示名称</option>
					<option value="分组名称">分组名称</option>
				</select>
				<input id="searchBox" class="topjui-searchbox"
				       style="width: 150px"/>
			</div>
			<ul id="deviceTree" class="ztree">
			</ul>
		</div>
	</div>
	<div data-options="region:'center'">
		<div class="topjui-layout" data-options="fit:true">
			<div class="ui-search-panel" style="height: 92px;" title="操作框"
			     data-options="region:'north',iconCls:'fa fa-search',border:false,split:false">
				<form id="searchForm">
					<p class="ui-fields" style="min-width:600px">
						<label class="ui-label">绑定状态:</label> <select id="bindState" name="bindState"
						                                              style="width:100px;height: 35px;padding-bottom:5px;">
						<option value="all">所有</option>
						<option value="none">未绑定</option>
						<option value="success">已绑定</option>
					</select>
						<label class="ui-label">设备号:</label><input id="simNo" name="simNo" data-toggle="topjui-textbox"
						                                           style="width:180px;">
						<input name="depIdSearch" id="depIdSearch" type="hidden" value="0"/>
						<input name="parentSim" id="parentSim" type="hidden" value=""/>
						<%--	<label class="ui-label">所属分组:</label>
							<input name="depIdSearch" id="depIdSearch" type="hidden" value="0"/>
							<input name="depNameSearch" id="departmentSearch" type="text" readonly
								   value="" class="depSearch" onclick="showMenuSearch();"/>--%>
						<%--			<label class="ui-label">创建时间</label>
									<input name="startTimeSearch" id="startTimeSearch"
										   class="topjui-datetimebox" editable="false"
										   data-options=" width:180">
									<label class="ui-label">至</label>
									<input name="endTime" id="endTimeSearch"
										   class="topjui-datetimebox" editable="false"
										   data-options=" width:180">--%>


						<a href="#" id="btn-search" class="topjui-menubutton btnmr" data-options="iconCls:'fa fa-search',
           btnCls:'topjui-btn'" style="margin-left: 5px;">搜索</a>

						<a href="#" id="btnBind" class="topjui-menubutton btnmr" data-options="iconCls:'fa fa-plus',
				   btnCls:'topjui-btn'" onclick="doBindDevice();">绑定</a>

						<a href="#" id="btnUnBind" class="topjui-menubutton btnmr" data-options="iconCls:'fa fa-trash',
				   btnCls:'topjui-btn-danger'" onclick="doUnBindDevice();">解绑</a>
					</p>
				</form>
			</div>
			<!--  Search panel end -->

			<!-- DataList  -->
			<div region="center" border="false">
				<table id="data-list"></table>
			</div>
		</div>
	</div>
</div>
<div id="commandWindow" style="width: 1; height: 0">
	<iframe scrolling="auto" id='commandIframe' frameborder="0" src="" style="width: 100%;
            height: 99%;"></iframe>
</div>
<script type="text/javascript" src="${ctx}/js/deviceBind/tree.js"></script>
<script type="text/javascript" src="${ctx}/js/common/package.js"></script>
<script type="text/javascript" src="${ctx}/js/common/base.js?v=11"></script>
<script type="text/javascript" src="${ctx}/js/common/DataGrid.js"></script>
<script type="text/javascript" src="${ctx}/js/deviceBind/deviceBind.js"></script>
<%--<style type="text/css">
	.datagrid-header-rownumber, .datagrid-cell-rownumber {
		width: 40px;
	}
</style>--%>
<script type="text/javascript">
	// 对Date的扩展，将 Date 转化为指定格式的String
	// 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符，
	// 年(y)可以用 1-4 个占位符，毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
	// 例子：
	// (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
	// (new Date()).Format("yyyy-M-d h:m:s.S")      ==> 2006-7-2 8:9:4.18
	Date.prototype.Format = function (fmt) { //author: meizz
		var o = {
			"M+": this.getMonth() + 1, //月份
			"d+": this.getDate(), //日
			"h+": this.getHours(), //小时
			"m+": this.getMinutes(), //分
			"s+": this.getSeconds(), //秒
			"q+": Math.floor((this.getMonth() + 3) / 3), //季度
			"S": this.getMilliseconds() //毫秒
		};
		if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
		for (var k in o)
			if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
		return fmt;
	}

	$(function () {
		//$("#startTimeSearch").iDatetimebox('setValue', new Date().Format("yyyy-MM-dd") + " 00:00:00");
		//$("#endTimeSearch").iDatetimebox('setValue', new Date().Format("yyyy-MM-dd hh:mm:ss"));
	});
</script>
<script type="text/javascript">
	$(function () {
		//创建设备树
		var deviceTreeId = "deviceTree";
		//设备
		DeviceTree.createTree(deviceTreeId);

		$('#searchBox').searchbox({
			searcher: function (value, name) {
				var filterTypeValue = $("#filterType").combobox('getText');
				var filterType = "";
				if ("设备号" == filterTypeValue) {
					filterType = 0;
				}
				if ("显示名称" == filterTypeValue) {
					filterType = 1;
				}
				if ("分组名称" == filterTypeValue) {
					filterType = 2;
				}
				DeviceTree.Treefilter(filterType, value);
			},
			prompt: '条件查询',
		});
		$('#filterType').combobox("setValue", "设备号");
	})


	/*	function doBindDevice() {
	 //获取checkbox选中的行的区域Id
	 var checkedItems = $('#data-list').datagrid('getChecked');
	 var simNos = [];
	 $.each(checkedItems, function (index, item) {
	 simNos.push('simNos=' + item.simNo);
	 });


	 var treeObj = $.fn.zTree.getZTreeObj("deviceTree");
	 var nodes = treeObj.getCheckedNodes(true);

	 if (nodes.length == 0) {
	 $.iMessager.alert("提示", "请勾选左侧树形指挥卡!", 'messager-warning');
	 return;
	 }
	 var node;
	 if (nodes.length > 0) {
	 node = nodes[0];
	 }
	 if (simNos.length == 0) {
	 $.iMessager.alert("提示", "请勾选列表北斗设备!", 'messager-warning');
	 return;
	 }
	 simNos.push('parentSim=' + node.simNo);
	 var params = simNos.join("&");
	 var url = path + "/deviceBind/deviceBind";
	 $.ajax(url, {
	 type: 'post',
	 dataType: 'json',
	 data: params,
	 success: function (result) {
	 if (result.success) {
	 var param = $("#searchForm").serializeObject();
	 $('#data-list').datagrid('reload', param);
	 }
	 else
	 $.iMessager.alert("提示", result.msg, 'messager-error');
	 },
	 });
	 }*/


	function doUnBindDevice() {
		//获取checkbox选中的行的区域Id
		var checkedItems = $('#data-list').datagrid('getChecked');
		var bindIds = [];
		$.each(checkedItems, function (index, item) {
			if (typeof (item.bindId) != "undefined") {
				bindIds.push('bindIds=' + item.bindId);
			}
		});

		if (bindIds.length == 0) {
			$.iMessager.alert("提示", "请勾选列表已绑定北斗设备!", 'messager-warning');
			return;
		}
		var params = bindIds.join("&");
		$.iMessager.confirm('提示', '你确定要解绑?', function (r) {
			if (r) {
				var url = path + "/deviceBind/deviceUnBind";
				$.ajax(url, {
					type: 'post',
					dataType: 'json',
					data: params,
					success: function (result) {
						if (result.success) {
							var param = $("#searchForm").serializeObject();
							$('#data-list').datagrid('reload', param);
						}
						else
							$.iMessager.alert("提示", result.msg, 'messager-error');
					},
				});
			}
		});
	}

	function doBindDevice() {
		$('#commandIframe')[0].contentWindow.document.body.innerText = "";
		$('#commandIframe')[0].src = path + '/deviceBind/deviceBindView';
		$('#commandWindow').dialog({
			width: 650,
			height: 480,
			modal: true,
			title: '指挥卡绑定',
			resizable: true,
			collapsible: false,
			onLoad: function () {

			}
		});
		$('#commandWindow').window('open');
		$('#commandWindow').window('center');//使Dialog居中显示

	}
</script>
</body>
</html>
